package com.nq.activaity.controller;

import com.nq.activaity.entity.StUserSignRecord;
import com.nq.activaity.service.IStUserSignRecordService;
import com.nq.common.Result;
import com.nq.common.ServerResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

 /**
 * @Description: 用户签到表
 * @Author: jeecg-boot
 * @Date:   2024-11-06
 * @Version: V1.0
 */
@RestController
@RequestMapping("/user/userSignRecord")
@Slf4j
public class StUserSignRecordController  {
	@Autowired
	private IStUserSignRecordService stUserSignRecordService;


	 /**
	  * 签到列表
	  * @param req
	  * @return
	  */
	 @RequestMapping({"list.do"})
	 @ResponseBody
	 public ServerResponse list(@RequestParam(name="month", required = false) String month,
										 HttpServletRequest req) {
		 ServerResponse response = stUserSignRecordService.list(month, req);
		 return response;
	 }

	 /**
	  * 签到
	  * @param req
	  * @param date
	  * @return
	  */
	 @RequestMapping({"sign.do"})
	 @ResponseBody
	 public ServerResponse sign(HttpServletRequest req, @RequestParam(name="date") String date) {
		 ServerResponse response = stUserSignRecordService.sign(req, date);
		 return response;
	 }


	 /**
	  * 提示文案：你已连续签到3天，还有4天将获得奖励
	  * @param req
	  * @return
	  */
	 @RequestMapping({"tips.do"})
	 @ResponseBody
	 public ServerResponse tips(HttpServletRequest req) {
		 ServerResponse response = stUserSignRecordService.tips(req);
		 return response;
	 }

	
	/**
	 *   添加
	 *
	 * @param stUserSignRecord
	 * @return
	 */
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody StUserSignRecord stUserSignRecord) {
		stUserSignRecordService.save(stUserSignRecord);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param stUserSignRecord
	 * @return
	 */
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody StUserSignRecord stUserSignRecord) {
		stUserSignRecordService.updateById(stUserSignRecord);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		stUserSignRecordService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.stUserSignRecordService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		StUserSignRecord stUserSignRecord = stUserSignRecordService.getById(id);
		if(stUserSignRecord==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(stUserSignRecord);
	}
//
//    /**
//    * 导出excel
//    *
//    * @param request
//    * @param stUserSignRecord
//    */
//    @RequestMapping(value = "/exportXls")
//    public ModelAndView exportXls(HttpServletRequest request, StUserSignRecord stUserSignRecord) {
//        return super.exportXls(request, stUserSignRecord, StUserSignRecord.class, "用户签到表");
//    }
//
//    /**
//      * 通过excel导入数据
//    *
//    * @param request
//    * @param response
//    * @return
//    */
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//        return super.importExcel(request, response, StUserSignRecord.class);
//    }

}
